package com.nbsystem.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbsystem.entity.ElcBlacklist;
import com.nbsystem.service.ElcBlacklistService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * (ElcBlacklist)表控制层
 *
 * @author makejava
 * @since 2021-06-01 15:18:21
 */
@RestController
@RequestMapping("elcBlacklist")
public class ElcBlacklistController {
    /**
     * 服务对象
     */
    @Resource
    private ElcBlacklistService elcBlacklistService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public ElcBlacklist selectOne(Integer id) {
        return this.elcBlacklistService.queryById(id);
    }


    @RequestMapping("list")
    public PageInfo<ElcBlacklist> queryAll(ElcBlacklist elcBlacklist, Integer rows, Integer page){
        PageHelper.startPage(page,rows);
        if (elcBlacklist.getDetail()!=null){
            elcBlacklist.setDetail("%" + elcBlacklist.getDetail()+"%");
        }
        List<ElcBlacklist> list = elcBlacklistService.queryAll(elcBlacklist);
        PageInfo<ElcBlacklist> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @RequestMapping("add")
    public String addElcBlackList(ElcBlacklist elcBlacklist){
        if (checkElc(elcBlacklist.getDetail()).equals("null")){
            return "false";
        }
        if (checkElc(elcBlacklist.getDetail()).equals("false")){
            return "like";
        }

        elcBlacklist.setCreateTime(new Date());
        elcBlacklist.setUpdateTime(new Date());
        elcBlacklistService.insert(elcBlacklist);
        return "success";
    }
    @RequestMapping("query/{id}")
    public ElcBlacklist queryElcBlackListById(@PathVariable Integer id){
        ElcBlacklist elcBlacklist = elcBlacklistService.queryById(id);
        return elcBlacklist;
    }
    @RequestMapping("update")
    public String updateElcBlackList(ElcBlacklist elcBlacklist){
        if (checkElc(elcBlacklist.getDetail()).equals("null")){
            return "false";
        }

        if (checkElc(elcBlacklist.getDetail()).equals("false")){
            return "like";
        }

        elcBlacklist.setUpdateTime(new Date());
        elcBlacklistService.update(elcBlacklist);
        return "success";
    }

    @RequestMapping("del/{id}")
    public String deleteElcBlackList(@PathVariable Integer id){
        elcBlacklistService.deleteById(id);
        return "success";
    }
    @RequestMapping("dels/{ids}")
    public String delElcBlackLists(@PathVariable Integer[] ids){
        elcBlacklistService.deleteByIds(ids);
        return "success";
    }


    @RequestMapping("listDel")
    public PageInfo<ElcBlacklist> querydels(ElcBlacklist elcBlacklist, Integer rows, Integer page){
        PageHelper.startPage(page,rows);
        if (elcBlacklist.getDetail()!=null){
            elcBlacklist.setDetail("%" + elcBlacklist.getDetail()+"%");
        }
        List<ElcBlacklist> list = elcBlacklistService.querydels(elcBlacklist);
        PageInfo<ElcBlacklist> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    @RequestMapping("resume/{id}")
    public String resumeDelete(@PathVariable Integer id){
        elcBlacklistService.resumeDelete(id);
        return "success";
    }

    @RequestMapping("queryAll")
    public List<ElcBlacklist> queryAll(ElcBlacklist elcBlacklist){
        return elcBlacklistService.queryAll(elcBlacklist);
    }

    @RequestMapping("checkElc")
    public String  checkElc(@RequestParam(defaultValue = "") String detail){
        if (detail==""){
            return "null";
        }
        return elcBlacklistService.queryByDetail(detail)+"";
    }

}

